package axisdownloadserver;
public class DownloadServerWebService {

    public String RequestServer(String aTitle){

        java.lang.Integer result1 = 0;
        java.lang.Integer result2 = 0;

        String stacktrace="";


        try { // Call Web Service Operation
            System.out.println("Setting up fileserver 192.168.3.125 service");
            firstpackage.FileServerWebService service = new firstpackage.FileServerWebService();
            System.out.println("Setting up fileserver 192.168.3.125 port");
            firstpackage.FileServerWebServicePortType port = service.getFileServerWebServiceHttpSoap11Endpoint();
            System.out.println("Querying fileserver 192.168.3.125 for: "+aTitle);
            result1 = port.checkFile(aTitle);
            System.out.println("Result1 = "+result1);

        } catch (Exception ex) {
            stacktrace += "Fileserver1 failed and did not respond";
        }
        try{
            System.out.println("Setting up fileserver 192.168.3.145 service");
            secondpackage.FileServerWebService service = new secondpackage.FileServerWebService();
            System.out.println("Setting up fileserver 192.168.3.145 port");
            secondpackage.FileServerWebServicePortType port = service.getFileServerWebServiceHttpSoap11Endpoint();
            System.out.println("Querying fileserver 192.168.3.145 for: "+aTitle);
            result2 = port.checkFile(aTitle);
            System.out.println("Result2 = "+result2);
        }
        catch(Exception ex){
            if(!stacktrace.equals(""))
                stacktrace+=", ";
            stacktrace += "Fileserver2 failed and did not respond ";
        }
        if (result1==0 && result2==0)
            return "No servers found with the file '"+aTitle+"' "+stacktrace;
        else if(result1>result2)
            return "Best server for the file '"+aTitle+"' found @ http://192.168.3.125:8080/axis2/services/FileServerWebService?wsdl with "+result1.toString()+"Kb/s \n"+stacktrace;
        else
            return "Best server for the file '"+aTitle+"' found @ http://192.168.3.145:8080/axis2/services/FileServerWebService?wsdl with "+result1.toString()+"Kb/s \n"+stacktrace;
    }
}